package com.AnywheeBt;

import java.util.Locale;
import android.content.Context;
import android.speech.tts.TextToSpeech;
public class SpeakTts {
	private Context mContext;
	private TextToSpeech mTTS;
	private boolean bSuccess=false;
	private boolean bUser=true;
	public SpeakTts(Context context) {
		mContext=context;		
		mTTS = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {			
			@Override
			public void onInit(int status) {
				if ( status == TextToSpeech.SUCCESS){ 
					Locale loc=Locale.getDefault();					
					int result = mTTS.setLanguage(loc);
					if (result == TextToSpeech.LANG_MISSING_DATA|| result == TextToSpeech.LANG_NOT_SUPPORTED){
					} else {
						bSuccess=true;
					}
				}
			}			
		},"com.iflytek.tts"); 		
	}	
	public void SetTextToSpeakTts(boolean bMode) {
		bUser=bMode;
	}
	public void TextToSpeakTts(String str) {		
	   if(bSuccess && bUser) mTTS.speak(str, TextToSpeech.QUEUE_FLUSH, null);
	} 
}